package yf.mall.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import yf.mall.entity.CourseCardEntity;
import yf.mall.service.CourseCardService;
import com.yf.response.R;


/**
 * 课程卡券Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Mon Oct 21 08:39:57 CST 2019
 */
@RestController
@RequestMapping("/courseCard")
public class CourseCardController {
    @Autowired
    private CourseCardService courseCardService;

    /**
     * 列表课程卡券
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:card:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<CourseCardEntity> courseCardList = courseCardService.queryList(params);
        return R.ok(new PageInfo(courseCardList));
    }

    /**
     * 查看课程卡券
     */
    @SysLog("查看课程卡券")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:card:info")
    public R info(@PathVariable("id") Long id) {
        CourseCardEntity courseCard = courseCardService.get(id);

        return R.ok(courseCard);
    }

    /**
     * 保存课程卡券
     */
    @SysLog("保存课程卡券")
    @RequestMapping("/save")
    @RequiresPermissions("course:card:save")
    public R save(CourseCardEntity courseCard) {
        courseCardService.save(courseCard);

        return R.ok(courseCard);
    }

    /**
     * 修改课程卡券
     */
    @SysLog("修改课程卡券")
    @RequestMapping("/update")
    @RequiresPermissions("course:card:update")
    public R update(CourseCardEntity courseCard) {
        courseCardService.update(courseCard);

        return R.ok(courseCard);
    }

    /**
     * 删除课程卡券
     */
    @SysLog("删除课程卡券")
    @RequestMapping("/delete")
    @RequiresPermissions("course:card:delete")
    public R delete(Long[]ids) {
        courseCardService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有课程卡券
     */
    @SysLog("所有课程卡券")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<CourseCardEntity> courseCardList = courseCardService.queryList(params);

        return R.ok(courseCardList);
    }

    /**
    @ModelAttribute
    public SearchParam<CourseCardEntity> searchParam(SearchParam<CourseCardEntity> params, CourseCardEntity courseCard) {
        if (courseCard != null) {
            params.setEntity(courseCard);
        }

        return params;
    }
 **/
    /***********自定义开始***********/
}
